# -*- coding:UTF-8 -*-
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QGridLayout, QWidget, QSpacerItem, QSizePolicy, \
    QHBoxLayout, QVBoxLayout, QLabel
from enum import Enum
from SplitWindow import SplitTimeWindow, SplitCountWindow, SplitSrtWindow, EditSrtWindow, ReplaceSrtWindow


class ButtonType(Enum):
    SplitTime = 1
    SplitCount = 2
    SplitSrt = 3
    SplitCustomTime = 4
    EditSrt = 5
    WordCheck = 6


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.replace_window = None
        self.edit_window = None
        self.srt_window = None
        self.count_window = None
        self.split_window = None
        self.setWindowTitle("胖虎的工具箱")
        # 创建中心小部件和布局
        central_widget = QWidget()
        self.setCentralWidget(central_widget)

        main_v_layout = QVBoxLayout()

        title_label = QLabel("视频分割")

        main_v_layout.addWidget(title_label)
        main_v_layout.addLayout(self.setup_video())

        srt_label = QLabel("文字处理")
        main_v_layout.addWidget(srt_label)
        main_v_layout.addLayout(self.setup_srt())

        central_widget.setLayout(main_v_layout)

    def setup_video(self):
        h_layout = QHBoxLayout()
        grid_layout = QGridLayout()

        time_button = QPushButton("指定时长")
        count_button = QPushButton("指定数量")
        srt_button = QPushButton("根据字幕分割")
        time_button.clicked.connect(lambda _: self.button_tap_event(ButtonType.SplitTime))
        count_button.clicked.connect(lambda _: self.button_tap_event(ButtonType.SplitCount))
        srt_button.clicked.connect(lambda _: self.button_tap_event(ButtonType.SplitSrt))
        buttons = [time_button, count_button, srt_button]
        positions = [(0, 0), (0, 1), (1, 0)]
        for button, position in zip(buttons, positions):
            grid_layout.addWidget(button, *position)

        h_layout.addStretch(1)
        h_layout.addLayout(grid_layout)
        h_layout.addStretch(1)

        return h_layout

    def setup_srt(self):
        h_layout = QHBoxLayout()
        grid_layout = QGridLayout()
        edit_button = QPushButton("查看与编辑字幕")
        check_button = QPushButton("违规词检测")

        edit_button.clicked.connect(lambda _: self.button_tap_event(ButtonType.EditSrt))

        check_button.clicked.connect(lambda _: self.button_tap_event(ButtonType.WordCheck))

        grid_layout.addWidget(edit_button, *(0, 0))
        grid_layout.addWidget(check_button, *(0, 1))
        h_layout.addStretch(1)
        h_layout.addLayout(grid_layout)
        h_layout.addStretch(1)
        return h_layout

    def button_tap_event(self, button_type):
        if button_type is ButtonType.SplitTime:
            self.split_window = SplitTimeWindow()
            self.split_window.show()
        elif button_type is ButtonType.SplitCount:
            self.count_window = SplitCountWindow()
            self.count_window.show()
        elif button_type is ButtonType.SplitSrt:
            self.srt_window = SplitSrtWindow()
            self.srt_window.show()
        elif button_type is ButtonType.EditSrt:
            self.edit_window = EditSrtWindow()
            self.edit_window.show()
        elif button_type is ButtonType.WordCheck:
            self.replace_window = ReplaceSrtWindow()
            self.replace_window.show()


if __name__ == '__main__':
    app = QApplication([])
    app.setWindowIcon(QIcon("clip_icon.png"))
    window = MainWindow()
    # window.resize(300, 200)
    window.show()
    app.exec()
